/*
 * ========================================================
 * Copyright(c) 2014 杭州龙骞科技-版权所有
 * ========================================================
 * 本软件由杭州龙骞科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * http://www.hzdracom.com/
 * ========================================================
 */
package com.shwread.httpsdk.http.face;

import java.util.HashMap;

import logic.bean.MessageInfo;
import logic.constants.AppConfig;
import logic.constants.Const;

import org.json.JSONObject;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.shwread.httpsdk.constant.ResultCode;
import com.shwread.httpsdk.http.base.AbstractHttpPostDracom;
import com.shwread.httpsdk.http.callback.ActionListener;


/**
 * @Project： Shwread
 * @Title：QryMsgByIdAction
 * @Description：
 * @Author：wayne
 * @Date：2015年4月30日下午1:57:33
 */
public class QryMsgByIdAction
        extends
        AbstractHttpPostDracom
{
	private String msgId;

	public QryMsgByIdAction(Context context, String msgId, ActionListener actionListener) {
	    super(context, "qryMsgById.do", actionListener);
	    this.msgId = msgId;
    }

	@Override
    public void getParameter(HashMap<String, String> parameter_map) {
		parameter_map.put("account", Const.phone_number);
		parameter_map.put("timeStamp", String.valueOf(timeStamp));
		parameter_map.put("msgId", msgId);
		parameter_map.put("enterpriseId", AppConfig.getEnterpriseId());
		parameter_map.put("cid", cid(Const.phone_number + Const.ACCOUNTTYPE + Const.CLIENTTYPE + timeStamp + msgId+ AppConfig.getEnterpriseId()));
    }

	@Override
    public void doResponseXml(String xml) {
		println(xml);
		System.out.println("阅读消息 -- msgViewId:"+msgId+",result:"+xml);
		int result = -1;
		try
		{
			JSONObject jsonObject = new JSONObject(xml);
			result = jsonObject.getInt("resultCode");
			if (result == 1000)
			{
				final String json = jsonObject.getString("returnObject");
				MessageInfo info = new Gson().fromJson(json, new TypeToken<MessageInfo>(){}.getType());
				
				listener.OK(info);
			}
			else
			{
				listener.ERROR(result, ResultCode.getResultText(result));
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
    }

	@Override
    protected void doRequestHeader(HashMap<String, String> header_map) {
	    
    }

	@Override
    public void dispose() {
	    
    }
	
}
